package com.ihm.projetihm_v1.image.fragmentManager;

import java.util.List;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;

import com.ihm.projetihm_v1.MyApplication;
import com.ihm.projetihm_v1.R;
import com.ihm.projetihm_v1.nf.Graphe;
import com.ihm.projetihm_v1.nf.LinkedPhoto;

/**
 * Fragment for list view
 * 
 * @author Adrien
 *
 */
public class ImageFragment
		extends ListFragment
{
	//+++++++++++//
	// CONSTANTS //
	//+++++++++++//
	
	public static enum MY_TABS
	{
		PHOTOS {
			@Override
			public int getTitleResID() {
				return R.string.title_section1;
			}
		},
		PANORAMAS {
			@Override
			public int getTitleResID() {
				return R.string.title_section2;
			}
		};
		public abstract int getTitleResID();
	}

	public static final String CST_ARG_SECTION_NUMBER = "section_number";
	
	/**
	 * the current view
	 */
	private View mView;
	
	//+++++++++//
	// METHODS //
	//+++++++++//

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		MyApplication app = (MyApplication) this.getActivity().getApplication();
		
        int tabPosition = this.getArguments().getInt(CST_ARG_SECTION_NUMBER);
        MY_TABS tab = MY_TABS.values()[tabPosition];
        
        ListAdapter listAdapter;
        if(app.isMainActivity())
        {
        	 listAdapter = new ImageListAdapter(
        			this.getActivity(),
        			R.layout.fragment_image_item,
        			app.getMainGraphsList(),
        			tab,app.isMainActivity());
        }else {
        	System.out.println("connect");
	    	 listAdapter = new ImageListAdapter(
	        			this.getActivity(),
	        			R.layout.fragment_image_item,
	        			app.getPhotoGraphsList(),
	        			tab,app.isMainActivity());
        }
    	this.setListAdapter(listAdapter);
           	
	}

    @Override
    public View onCreateView(
    		LayoutInflater inflater,
    		ViewGroup container,
            Bundle savedInstanceState)
    {
		if (this.mView == null)
		{
	        this.mView = this.getViewList(inflater);
		}
        return this.mView;
    }
	
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    /**
     * to get the view for list of list
     * @param inflater which can inflate views
     * @return the view for list of list
     */
    private View getViewList(LayoutInflater inflater)
    {
    	View view = inflater.inflate(R.layout.fragment_main, null);
        return view;
    }
}
